package com.wolfalpha.utron.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import com.wolfalpha.utron.R;
import com.wolfalpha.utron.activity.base.BaseNormal2Activity;
import com.wolfalpha.utron.service.IdeaService;
import com.wolfalpha.utron.service.impl.IdeaServiceImpl;
import com.wolfalpha.utron.ui.UIHelper;
import com.wolfalpha.utron.utils.ThreadPoolUtils;

/**
 * 创意详情界面
 * <p/>
 * Created by luodon on 15/8/27.
 */

public class IdeaReplyActivity extends BaseNormal2Activity {

    private EditText etContent; //输入框

    private IdeaService ideaService = null;

    private int ideaId = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle bundle = getIntent().getExtras();
        if (bundle == null || !bundle.containsKey("ideaId")) {
            finish();
        } else {
            ideaId = bundle.getInt("ideaId");
        }

        setContentView(R.layout.activity_idea_reply);
        ideaService = new IdeaServiceImpl();

        intiView();
    }

    /**
     * 初始化界面
     */
    private void intiView() {
        setTvTitle("添加评论");
        setRightIcon(R.mipmap.app_finish);

        etContent = (EditText) findViewById(R.id.et_idea_reply);
    }

    @Override
    public void rightOperation() {
        if (TextUtils.isEmpty(etContent.getText().toString().trim())) {
            UIHelper.ToastMessage(IdeaReplyActivity.this, "您还未输入内容");
            return;
        }
        //发布评论
        ThreadPoolUtils.execute(new Runnable() {
            @Override
            public void run() {
                boolean result = ideaService.doComment(ideaId, etContent.getText().toString().trim(), 0);
                if (result) {
                    finish();
                } else {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            UIHelper.ToastMessage(IdeaReplyActivity.this, "发布失败，请稍后再试");
                        }
                    });
                }
            }
        });

        finish();
    }

}
